package com.example.yichuangyun.mvvm.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.yichuangyun.databinding.ItemReportBinding;
import com.example.yichuangyun.model.company.GsBaseInfoModel;

import java.util.List;

/**
 * 企业年报
 */
public class ReportAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final Context context;
    private final List<GsBaseInfoModel.CompanyReportModel> data;

    public ReportAdapter(Context context, List<GsBaseInfoModel.CompanyReportModel> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemReportBinding binding = ItemReportBinding.inflate(LayoutInflater.from(context), parent, false);
        return new MyViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder) {
            MyViewHolder myViewHolder = (MyViewHolder) holder;
            GsBaseInfoModel.CompanyReportModel model = data.get(position);
            myViewHolder.binding.tvReportName.setText(model.getReportName());
            myViewHolder.binding.tvReportDate.setText(model.getReportDate());
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {

        ItemReportBinding binding;

        public MyViewHolder(ItemReportBinding itemReportBinding) {
            super(itemReportBinding.getRoot());
            binding = itemReportBinding;
        }
    }
}
